home *** CD-ROM | disk | FTP | other *** search
- class Heroes.Follower extends Heroes.WorldObject
- {
- var speechTimer;
- var walkDistance;
- var maxDistance;
- var x;
- var z;
- var graphics;
- var facing;
- var state = "stand";
- var slowSoundCount = 0;
- var fastSoundCount = 0;
- var maxSpeed = 9;
- var facingDirection = 1;
- function Follower()
- {
- super();
- this._visible = true;
- this.speechTimer = 4.9e-324;
- this.walkDistance = 60;
- this.maxDistance = 150;
- this.playSound("walkies");
- }
- function onEnterFrame()
- {
- this.maxSpeed = this._parent.player.getRunningSpeed() - 2;
- var _loc7_ = 10;
- var _loc10_ = this._parent.player.x - this.x;
- var _loc9_ = this._parent.player.z - this.z;
- var _loc23_ = this._parent.player.z - this._parent.player.prevZ;
- var _loc15_ = this._parent.player.x - this._parent.player.prevX;
- var _loc4_ = Math.sqrt(Math.pow(_loc10_,2) + Math.pow(_loc9_,2));
- var _loc19_ = _loc10_ * _loc15_ + _loc9_ * _loc23_;
- var _loc5_ = this.walkDistance * 0.75;
- if(_loc4_ < _loc5_ || _loc19_ < 0 || _loc4_ > this.walkDistance)
- {
- _loc23_ = this._parent.player.z - this._parent.player.prevZ;
- var _loc25_ = this._parent.player.facingDirection * 25;
- var _loc18_ = this._parent.player.x + _loc15_ * _loc7_ - _loc25_;
- var _loc17_ = this._parent.player.z + _loc23_ * _loc7_;
- var _loc20_ = _loc18_ - this.x;
- var _loc21_ = _loc17_ - this.z;
- var _loc11_ = Math.atan2(_loc21_,_loc20_);
- var _loc24_ = Math.floor(_loc18_ - this.walkDistance * Math.cos(_loc11_));
- var _loc22_ = Math.floor(_loc17_ - this.walkDistance * Math.sin(_loc11_));
- var _loc16_ = _loc24_ - this.x;
- var _loc14_ = _loc22_ - this.z;
- var _loc8_ = Math.sqrt(Math.pow(_loc16_,2) + Math.pow(_loc14_,2));
- var _loc3_ = _loc8_ / (_loc7_ + 1);
- var _loc6_ = _loc16_ / _loc8_;
- var _loc13_ = _loc14_ / _loc8_;
- if(_loc4_ < _loc5_)
- {
- var _loc12_ = (_loc5_ - _loc4_) * 0.75 / _loc5_;
- _loc6_ -= _loc10_ * _loc12_;
- _loc13_ -= _loc9_ * _loc12_;
- }
- if(_loc3_ > this.maxSpeed)
- {
- _loc3_ = this.maxSpeed;
- }
- if(_loc4_ > this.maxDistance)
- {
- this._parent.player.stopRunning();
- }
- if(_loc3_ > 1.5)
- {
- this.x += _loc6_ * _loc3_;
- this.z += _loc13_ * _loc3_;
- this.setState("walk");
- if(_loc3_ > 2)
- {
- if(_loc6_ < 0)
- {
- this.facingDirection = -1;
- this.face("left");
- }
- if(_loc6_ > 0)
- {
- this.facingDirection = 1;
- this.face("right");
- }
- }
- }
- else
- {
- this.faceDog();
- this.setState("stand");
- }
- }
- else
- {
- this.faceDog();
- this.setState("stand");
- }
- super.onEnterFrame();
- this.drawLead();
- }
- function drawLead()
- {
- var _loc7_ = this._parent.player.x - this.x;
- var _loc9_ = this._parent.player.z - this.z;
- var _loc8_ = Math.sqrt(Math.pow(_loc7_,2) + Math.pow(_loc9_,2));
- this.graphics.arm._rotation = (- Math.abs(_loc7_)) / 2;
- var _loc2_ = {x:this.graphics.arm.leadTop._x,y:this.graphics.arm.leadTop._y};
- this.graphics.arm.localToGlobal(_loc2_);
- this.graphics.globalToLocal(_loc2_);
- this.graphics.leadBack._x = _loc2_.x;
- this.graphics.leadBack._y = _loc2_.y;
- this.graphics.leadFront._x = _loc2_.x;
- this.graphics.leadFront._y = _loc2_.y;
- var _loc5_ = {x:this._parent.player.graphics.leadBottom._x,y:this._parent.player.graphics.leadBottom._y};
- this._parent.player.graphics.localToGlobal(_loc5_);
- this.graphics.globalToLocal(_loc5_);
- var _loc4_ = _loc5_.x - _loc2_.x;
- var _loc3_ = _loc5_.y - _loc2_.y;
- var _loc6_ = 30 * this.maxDistance / _loc8_;
- if(_loc6_ > 40)
- {
- _loc6_ = 40;
- }
- this.graphics.leadFront.clear();
- this.graphics.leadBack.clear();
- if(this._parent.player.z < this.z)
- {
- this.graphics.leadFront.lineStyle(2,Heroes.Tools.getPlayerCollarColour(),100);
- this.graphics.leadFront.moveTo(0,0);
- this.graphics.leadFront.curveTo(_loc4_ / 2,_loc3_ / 2 + _loc6_,_loc4_,_loc3_);
- }
- else
- {
- this.graphics.leadBack.lineStyle(2,Heroes.Tools.getPlayerCollarColour(),100);
- this.graphics.leadBack.moveTo(0,0);
- this.graphics.leadBack.curveTo(_loc4_ / 2,_loc3_ / 2 + _loc6_,_loc4_,_loc3_);
- }
- }
- function faceDog()
- {
- if(this._parent.player.x < this.x)
- {
- this.facingDirection = -1;
- this.face("left");
- }
- else
- {
- this.facingDirection = 1;
- this.face("right");
- }
- }
- function setState(newState)
- {
- if(this.state != newState && this.state != "levelComplete")
- {
- this.state = newState;
- this.graphics.gotoAndPlay(newState);
- }
- }
- function face(newDirection)
- {
- if(newDirection != this.facing)
- {
- if(newDirection == "left")
- {
- this.facingDirection = -1;
- }
- else
- {
- this.facingDirection = 1;
- }
- this.facing = newDirection;
- §§push(this.gotoAndStop(newDirection));
- }
- }
- function playSound(soundName)
- {
- if(soundName == "step1" || soundName == "step2" || soundName == "goodboy" || soundName == "letsgo" || soundName == "walkies")
- {
- super.playSound(soundName);
- }
- else if(getTimer() - this.speechTimer > 2500)
- {
- this.speechTimer = getTimer();
- pi.AudioLibrary.stopSound("walkies");
- pi.AudioLibrary.stopSound("comeontimesticking");
- pi.AudioLibrary.stopSound("goodboy");
- pi.AudioLibrary.stopSound("letsgo");
- pi.AudioLibrary.stopSound("steady");
- pi.AudioLibrary.stopSound("new_moveit");
- pi.AudioLibrary.stopSound("new_easymate");
- pi.AudioLibrary.stopSound("new_waitforme");
- pi.AudioLibrary.stopSound("steady");
- pi.AudioLibrary.stopSound("hupup");
- pi.AudioLibrary.stopSound("sit");
- if(soundName == "new_easymate" || soundName == "new_easythere" || soundName == "new_waitforme" || soundName == "steady")
- {
- this.slowSoundCount = this.slowSoundCount + 1;
- }
- if(soundName == "new_moveit" || soundName == "hupup")
- {
- trace("soundName=" + soundName);
- this.fastSoundCount = this.fastSoundCount + 1;
- }
- super.playSound(soundName);
- }
- }
- function playFasterSound()
- {
- switch(this.fastSoundCount % 2)
- {
- case 0:
- this.playSound("hupup");
- break;
- case 1:
- this.playSound("new_moveit");
- }
- }
- function playSlowerSound()
- {
- switch(this.slowSoundCount % 3)
- {
- case 0:
- this.playSound("steady");
- break;
- case 1:
- this.playSound("new_easymate");
- break;
- case 2:
- this.playSound("new_waitforme");
- }
- }
- }
-